<include file="Public/head"/>

<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>
            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="cf">
                            <form class="form-inline" action="" method="get">
                                <a class="btn btn-info" href="{:U('append')}" value="">发布课程表</a>
                                <label class="inline">所属班级</label>
                                <select name="class_id" id="class_id" class="form-control">
                                        <option value="0">--请选择班级--</option>
                                    <volist name="class"  id="val">
                                        <option <if condition="I('class_id') eq $val['id']">selected</if> value="{:$val['id']}">{:$val['name']}</option>
                                    </volist>
                                </select>
                                <label class="inline">&nbsp;&nbsp;文章排序：</label>
                                <select name="order" id="order" class="form-control">
                                    <option value="desc" <if condition="I('order') eq desc">selected</if>>发布时间降序</option>
                                    <option value="asc" <if condition="I('order') eq asc">selected</if> >发布时间升序</option>

                                </select>


                                <button type="button" onclick="sou()" class="btn btn-purple btn-sm">
                                    <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                    搜索
                                </button>
                            </form>
                        </div>
                        <div class="space-4"></div>
                        <form id="form" method="post" action="{:U('del')}">
                            <table class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th>所属班级</th>
                                    <th>标题</th>
                                    <th>发布时间</th>
                                    <th>日期</th>
                                    <th>是否显示</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <volist name="data" id="val">
                                    <tr>
                                        <td>{$val['class_name']}</td>
                                        <td>{$val['title']}</td>
                                        <td>{$val['add_time']|date="Y-m-d H:i:s",###}</td>
                                        <td>{$val['start']|date="Y年m月d日",###}~{$val['end']|date="Y年m月d日",###}</td>
                                        <td>
                                            <select name="is_show" id="is_show" onchange="setStatus(this)">
                                                <option <if condition="$val['is_del'] eq 1 ">selected='selected'</if> value="{$val['id']}-1">显示</option>
                                                <option <if condition="$val['is_del'] eq 0 ">selected='selected'</if> value="{$val['id']}-0">不显示</option>
                                            </select>
                                        </td>
                                        <td><a href="{:U('edit',array('id'=>$val['id']))}"><i
                                                class="ace-icon fa fa-pencil bigger-100"></i>修改</a>&nbsp&nbsp;<a
                                                href="{:U('detail',array('id'=>$val['id']))}"><i
                                                class="ace-icon fa "></i>查看</a>&nbsp&nbsp;<a
                                                href="javascript:;" val="{:U('del',array('id'=>$val['id']))}" class="del"><i
                                                class="ace-icon fa fa-trash-o bigger-100 red"></i>删除</a></td>
                                    </tr>
                                </volist>
                                <if condition="empty($data)">
                                    <tr align="center">
                                        <td colspan="6">没有课程信息！</td>
                                    </tr>
                                </if>
                                </tbody>
                            </table>
                        </form>
                        {$page}
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function () {
        $(".check-all").click(function () {
            $(".aids").prop("checked", this.checked);
        });
        $(".aids").click(function () {
            var option = $(".ids");
            option.each(function (i) {
                if (!this.checked) {
                    $(".check-all").prop("checked", false);
                    return false;
                } else {
                    $(".check-all").prop("checked", true);
                }
            });
        });
        $(".del").click(function () {
            var url = $(this).attr('val');
            bootbox.confirm({
                title: "系统提示",
                message: "是否要该周课程？",
                callback: function (result) {
                    if (result) {
                        window.location.href = url;
                    }
                },
                buttons: {
                    "cancel": {"label": "取消"},
                    "confirm": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
        });
    })
//ajax更改状态
function setStatus(a){
    var is_show = a.value;
    $.ajax({
        url: "{:U('Course/is_show')}",
        type: 'post',
        dataType: 'json',
        data: {'is_show': is_show},
        success : function (res){
            if(res.res==1){
                 bootbox.dialog({
                    title: '友情提示：',
                    message: '修改'+res.msg,
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }else{
               bootbox.dialog({
                    title: '友情提示：',
                    message: '修改'+res.msg,
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;  
            }
        }
    })
    
}

//搜索
function sou(){
    var class_id = $('#class_id').val();
    var order = $('#order').val();
    var param = '';
    if(class_id != 0){
        param += '/class_id/'+class_id;
    }
    param += '/order/'+order;
    var url = '__APP__/Admin/Course/index'+param+'.html';
    location.href = url;
}
</script>
</body>
</html>
